package br.ufc.ck0017.ir.translate;

import br.ufc.ck0017.ir.tree.CJUMP.LogicalOperator;
import br.ufc.ck0017.ir.tree.IR;
import br.ufc.ck0017.ir.tree.IRNode;
import br.ufc.ck0017.temp.Label;

public class AndCx extends TranslateCx {
    private final TranslatedExpression firstExpression;
    private final TranslatedExpression secondExpression;

    public AndCx(TranslatedExpression firstExpression, TranslatedExpression secondExpression) {
        this.firstExpression = firstExpression;
        this.secondExpression = secondExpression;
    }

    @Override
    public IRNode unCx(Label trueLabel, Label falseLabel) {
        Label label = new Label();

        return IR.SEQ(IR.CJUMP(LogicalOperator.EQ, firstExpression.unEx(), IR.TRUE, label, falseLabel),
                      secondExpression.unCx(trueLabel, falseLabel));
    }
}
